package com.my;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.my.common.CommonJsonResult;
import com.my.config.ds.datarouting.DBProperties;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.util.FileCopyUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by wt on 2017/12/4.
 */
@SpringBootTest
public class Something {

    @Test
    public void test1() {
        Object obj = null;
        String s = JSON.toJSONString(obj);
        System.out.println(s);
    }

    @Test
    public void test2() {
        Object obj = null;
        String s = JSON.toJSONString(obj);
        System.out.println(s);
    }

    @Test
    public void test3() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse("2017-11-02 10:02:25");
        long time = date.getTime();
        System.out.println(time);

    }

    @Test
    public void test4() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Long[] longs = {1510821067283L, 1509611467283L, 1512030667283L, 1514449867283L, 1513240267283L};
        for (int i = 0; i < longs.length; i++) {
            String format = simpleDateFormat.format(new Date(longs[i]));
            System.out.println(format);
        }

    }


    @Test
    public void test5() throws ParseException {
        CommonJsonResult commonJsonResult = new CommonJsonResult();
        commonJsonResult.setResultList(Lists.newArrayList("13147119605", "13810315896", "15861684221"));

        System.out.println(JSON.toJSONString(commonJsonResult));

    }

    @Test
    public void test6() throws ParseException {

        Date start = new LocalDate(2016, 2, 8).toDate();
        Date end = new LocalDate(2017, 1, 27).toDate();

        Integer days = Days.daysBetween(new DateTime(start), new DateTime(end)).getDays();
        System.out.println(days);

    }

    @Test
    public void test7() throws ParseException {
        Date start = new LocalDate(1994, 12, 12).toDate();
        System.out.println(start.getTime());


    }

    @Test
    public void test8() throws ParseException {
        String dateStr = "2018/2/6 9:01";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = simpleDateFormat.parse(dateStr);

        System.out.println(new Date(date.getTime()));

        String format = new SimpleDateFormat("yyyy-MM-dd").format(date);
        System.out.println(format);

    }

    @Test
    public void test9() throws Exception {
        Resource res = new ClassPathResource("common.properties");
        EncodedResource encRes = new EncodedResource(res, "UTF-8");
        String content = FileCopyUtils.copyToString(encRes.getReader());
        System.out.println(content);

    }

    @Test
    public void test10() throws Exception {
        ArrayList<Integer> list = Lists.newArrayList(1, 2);
        System.out.println(list);

    }

    @Test
    public void test11() throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DBProperties.class);
        DBProperties dbProperties = context.getBean(DBProperties.class);


//        DBProperties dbProperties = new DBProperties();
        System.out.println("111111111");
        System.out.println(dbProperties.getAnalysisPassword());

    }


    public static void main(String[] args) {
        List list = new ArrayList<FavoriteMsg>();

        FavoriteMsg favoriteMsg = new FavoriteMsg();
        favoriteMsg.setSource_id(57);
        favoriteMsg.setType_id(2);
        list.add(favoriteMsg);

        FavoriteMsg favoriteMsg2 = new FavoriteMsg();
        favoriteMsg2.setSource_id(58);
        favoriteMsg2.setType_id(2);
        list.add(favoriteMsg2);

        System.out.println(JSON.toJSONString(list));

    }


}
